
//import javafx.scene.text.Font;
//import javafx.scene.text.FontPosture;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author habib <imamhabibpamungkas@gmail.com>
 */
public class Modus extends UkuranPemusatan {

    public static String hitung(Data data) {
        
        double[] dataF = new double[data.getSize()];

        int frek, jml;
        double fm, m = 0;
        jml = data.getSize();

        for (int i = 0; i < jml; i++) {
            frek = 0;
            for (int j = 0; j < jml; j++) {
                if (data.getData(j) == data.getData(i)) {
                    frek++;
                    dataF[i] = frek;
                }
            }

        }

        label:
        for (int i = 0; i < jml; i++) {
            if (i > 0) {
                for (int j = 0; j < i; j++) {
                    if (data.getData(i) == data.getData(j) && dataF[i] == dataF[j]) {
                        break label;
                    }
                }
            }
        }

        fm = 0;
        for (int i = 0; i < jml; i++) {
            if (dataF[i] > fm) {
                fm = dataF[i];
                m = data.getData(i);
            }
        }

        int x = 1;
        for (int i = 1; i < jml; i++) {
            if (dataF[0] == dataF[i]) {
                x++;
            }
        }
        String hasil = "";
        if (jml < 3 || x == jml) {
            return "Tidak ada modus";


        }
        return m + "";
    }
}
